<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>

<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>
<title>_${customer.customerName}_创建任务</title>

<script type="text/javascript">
  $(function() {
	var size='${orderList.size()}';
	if(size==0){
// 	   $("#btn_pre").attr("disabled", true);
// 	   $("#btn_pre").attr("class", "btn");
// 	   $("#btn_pre").val("所有订单已生成任务");
// 	   $("#btn_pre").attr("onclick",""); 
	}
  });
  
  
    //指派任务
	function task(taskId){
	
	  var btn_id="#btn_"+taskId;
	  var picker_id="#picker_"+taskId;
	  var status_id="#status_"+taskId;
	  
	  var jobuuid=$(picker_id).val();
	
	  if(jobuuid==''){
	     alert_message("失败！","必须选择一个执行人！","error",10000);
	    $(picker_id).focus();
	    return;
	  }
	  
	  $.ajax({
			type : 'post',
			url : '${ctx}/workTask/ajaxCommandTask',
			data : {
				jobuuid : jobuuid,
				taskId : taskId
			},
			dataType : 'json',
			success : function(data) {
			    var msg=data.msg;
				if (msg == "success") {
					alert_message("成功！","任务分配成功了！","success",10000);
					 $(btn_id).attr("disabled", true);
	                 $(btn_id).attr("class", "btn");
	                 $(btn_id).val("已指派");
	                 $(picker_id).attr("disabled", true);
	                 $(status_id).html("已指派任务");
				}else if(msg=="token"){
				   alert_message("失败！","此任务已经被分配过了！","error",10000);
				    location.reload();
				}else {
					 alert_message("系统错误！","请检查网络连接是否正常！","error",10000);
				}
			},
			error : function() {
				 alert_message("系统错误！","请检查网络连接是否正常！","error",10000);
			}
		});
	}
</script>
</head>

<body>

	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="1" bgcolor="#999">创建作业任务</th>
		</thead>
		<tr >
		   <td>
		     
		 <form class="form-search" id="queryForm" method="post" action="${ctx}/focusBatchTask/preTask" style="margin-top: 10px;"> 
			 	
			 	<label style="margin-left: 10px;"><a href="#" data-toggle="popover" title="订单分拣策略" data-content="1.组合策略：将最大程度平衡集中SKU和拣货路径优化。2.SKU集中：尽可能将需求相同SKU的订单生成在同任务；3.单品合拣：任务中只有单一SKU需求；4：整箱分拣：将能够满足直接拣选整箱货物的订单生成任务">拣货策略：</a></label>
				<select class="input-medium"  id="tactics" name="tactics">
				        <option value="" >组合策略</option>
				        <option value="SKU" >SKU集中策略</option>
				        <option value="path" >路径优化策略</option>
				        <option value="singleSKU" >单品合拣策略</option>
				        <option value="wholeBox" >整箱分拣策略</option>
				</select> 
			 	 
			 	<label style="margin-left: 10px;"><a href="#" data-toggle="popover" title="订单分拣容量" data-content="每个分拣任务最大处理的订单数量">任务容量：</a></label>
				<select class="input-medium" id="taskcount" name="taskcount">
				        <option value="5">5单</option>   
				        <option value="20">20单</option>  
				        <option value="50">50单</option>  
				        <option value="100">100单</option>
				        <option value="200">300单</option>
				        <option value="1000">1000单</option>
				        <option value="2000">2000</option>
				 </select>
				 
				 <input type="hidden" name="batchCode" value="${batch.batchTaskCode}">
				 <input type="hidden" name="pickType" value="${batch.type}">
				
				<input type="submit" value="生成拣货任务" class="btn btn-primary offset1" id="btn_pre">
				
		    </form>
		    
		   </td>
		</tr>
	</table>
	
	
	<!-- 已创建任务 -->
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#CCC">已创建任务</th>
		</thead>
		<thead><tr>
			    <th>序号</th>
			    <th style="width: 100px;">批次编号</th>
			    <th style="width: 100px;">任务编号</th>
			    <th>订单数量</th>
			    <th>创建人</th>
			    <th>任务状态</th>
			    <th>执行人</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		<c:if test="${empty taskList or taskList.size() eq 0}">
	       <tr><td colspan="19" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td></tr>
	    </c:if>
		<c:forEach items="${taskList}" var="t" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			 <td>
			    <c:if test="${t.status eq '1'}">
					<input class="btn btn-info" type="button" value="指派" id="btn_${t.id}" onclick="task('${t.id}');" />
				</c:if>
			    <c:if test="${t.status ne '1'}">
			        <input class="btn" type="button" value="已分配" disabled="disabled" />
			    </c:if>
			 </td>
		</c:forEach>
		</tbody>
	</table>
	
    <!-- 订单信息 -->
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
	<thead>
		<th style="vertical-align: middle; color: white; " colspan="12" bgcolor="#CCC">未处理订单信息</th>
	</thead>
	<thead><tr>
		    <th>序号</th>
		    <th>订单号</th>
		    <th>运单号</th>
		    <th>操作</th>
		</tr></thead>
	<tbody>
	<c:if test="${empty orderList or orderList.size() eq 0}">
	   <tr><td colspan="19" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td></tr>
	</c:if>
	<c:forEach items="${orderList}" var="o" varStatus="i">
		<tr>
		   <td>${i.count}</td>
		   <td>${o.ordeno}</td>
		   <td>${o.waybillNo}</td>
		   <td><a href="#ordersDetailed" onclick="getAjaxOrders('${o.ordeno}')"
								role="button" class="btn btn-small" data-toggle="modal"> 订单详情 </a>

							<a href="#itemsDetailed" onclick="getAjaxItems('${o.ordeno}')"
								role="button" class="btn btn-small" data-toggle="modal"> 商品详情 </a></td>
	</c:forEach>
	</tbody>
</table>
<div style="display: none; width: 1000" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="ordersDetailed">
			<div class="modal-header">
				<h3 id="myModalLabel">
					订单详细信息
				</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed"
					id="modalBodyOrders"></table>
			</div>
			<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>

		<div style="display: none; width: 1000" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="itemsDetailed">
			<div class="modal-header">
				<h3 id="myModalLabel">
					商品详细信息
				</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed"
					id="modalBodyItems"></table>
			</div>
			<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					关闭
				</button>
			</div>
		</div>
</body>
</html>
